import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <pre>
 * 
 * 
 * </pre>
 *
 * 
 * @since 2014.11.09
 * @author cloud
 *
 */

public class SchoolManager {
	private List<Person> personList;
	
	public SchoolManager(){
		personList = new ArrayList<Person>();
	}
	
	public void addPerson(Person p) throws DuplicatedException{
		for (Person person : personList) {
			if(person.getSsn().equals(p.getSsn()))
				throw new DuplicatedException();
		}
		
		personList.add(p);
	}
	
	public boolean updatePerson(Person p){
		int index = 0;
		for (Person person : personList) {
			if(person.getSsn().equals(p.getSsn())){
				personList.set(index, p);
				return true;
			}
				
			index++;
		}
		return false;
	}
	
	public List<Person> getPersonList(){
		return personList;
	}
	
	public Person searchPerson(String ssn){
		for (Person person : personList) {
			if(person.getSsn().equals(ssn)){
				return person;
			}
		}
		
		return null;
	}
	
	public boolean deletePerson(String ssn){
		for (Person person : personList) {
			if(person.getSsn().equals(ssn)){
				personList.remove(person);
				return true;
			}
		}
		
		return false;
	}
}
